package leetcode;

import java.util.Arrays;

/**
 * @Project : ProgrammingExercises
 * @Package : Leetcode
 * @File : Q2558.java
 * @Author : WangRuoyu
 * @Date 2023/2/20 17:47
 */
public class Q2558 {
    public long pickGifts(int[] gifts, int k) {
        long res = 0;
        int len = gifts.length;

        for (int i = 0; i < k; ++i) {
            Arrays.sort(gifts);
            gifts[len - 1] = (int) Math.sqrt(gifts[len - 1]);
        }

        for (int gift : gifts) {
            res += gift;
        }
        return res;
    }

    public static void main(String[] args) {
        Q2558 sl = new Q2558();
        int[] gifts = {25, 64, 9, 4, 100};
        int k = 4;
        System.out.println(sl.pickGifts(gifts, k));
    }
}